package com.autocloud.util;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Objects;

/**
 * @author zhongwb
 * @version 1.0
 * @description
 * @date 2019/12/3 8:49 下午
 */
public class ByteUtil {

    public static String toString(List<byte[]> bytes) throws UnsupportedEncodingException {

        if (bytes == null || bytes.size() == 0)
            return null;

        int lengthOfByte = bytes.stream().filter(Objects::nonNull).mapToInt(o -> o.length).sum();

        byte[] res = new byte[lengthOfByte];
        int countLength = 0;

        for (byte[] b : bytes) {
            if (b != null) {
                System.arraycopy(b, 0, res, countLength, b.length);
                countLength += b.length;
            }
        }

        return new String(res, "utf-8");
    }

}
